package org.client.otdr;

import java.util.List;

import org.openems.entity.Key;
import org.openems.entity.TableEntity;

import framework.AccessorHelper;

public class EventTableCreator {

	public void create(AccessorHelper helper) {
		OTDRID id = OTDRID.get();
		TableEntity table = (TableEntity)helper.getAccessor().get(id.TABLE);
		table.getRowDataList().clear();
		String[] title = {"No", "Type", "Distance[km]", "Level[dB]", "Address"};
		table.setTitle(title);
		
		List<Key> keys = helper.getKeyList(id.MARKERLIST);
		
		for (Integer row = 0; row < keys.size(); row++) {
			String[] cols = new String[title.length];
			for (int col = 0; col < cols.length; col++) {
				if (col == 0) {
					cols[col] = ((Integer)(row+1)).toString();
				}
				else if (col == 1) {
					cols[col] = "Connector";
				}
				else if (col == 2) {
					cols[col] = String.format("%.3f", helper.getMarkerX(keys.get(row)));
				}
				else if (col == 3) {
					cols[col] = String.format("%.3f", helper.getMarkerY(keys.get(row)));
				}
				else if (col == 4) {
					cols[col] = helper.getMarkerText(keys.get(row));
				}
				else {
					cols[col] = String.valueOf(Math.random());
				}
			}
			table.getRowDataList().add(cols);
		}
		helper.getAccessor().put(table);
	}
}
